package com.yingjie.yingjieorder.config.orderMq;



import com.yingjie.yingjieorder.common.RabiitMqConst;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


@Configuration
public class DelayRabbitmqConfig {

    //自定义延迟交换机
    @Bean
    public CustomExchange customExchange(){
        Map<String, Object> arguments=new HashMap<>();
        arguments.put("x-delayed-type","direct");
        return new CustomExchange(RabiitMqConst.DELAY_EXCHANGE,"x-delayed-message",true,false,arguments);
    }

    @Bean
    public Queue queue(){

        return QueueBuilder.durable(RabiitMqConst.DELAY_ORDER_QUEUE).build();
    }

    @Bean
    public Binding binding(CustomExchange customExchange, Queue queue){
        return BindingBuilder.bind(queue).to(customExchange).with(RabiitMqConst.DELAY_ORDER_QUEUE).noargs();
    }

}
